﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StoreWeb.ajax
{
    public partial class memberGrade : System.Web.UI.Page
    {
        //BLL.Role rolebll = new BLL.Role();
        BLL.memberGrade memberGradebll = new BLL.memberGrade();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int row = 0;
                if (!string.IsNullOrEmpty(Request["action"]) && Request["action"] == "delete")
                {
                    Response.Write((memberGradebll.Delete(Convert.ToInt32(Request["id"])) ? "1" : "0"));
                }
                else
                {
                    Model.memberGrade ne = new Model.memberGrade();
                    if (!string.IsNullOrEmpty(Request["id"]))
                    {
                        ne = memberGradebll.GetModel(Convert.ToInt32(Request["id"]));
                        ne.grade = Request["grade"];
                        ne.discountrate = Request["discountrate"];
                        row = memberGradebll.Update(ne) ? 2 : 0;
                    }
                    else
                    {
                        ne.grade = Request["grade"];
                        ne.discountrate = Request["discountrate"];
                        row = memberGradebll.Add(ne) > 0 ? 1 : 0;
                    }
                    if (row == 1)
                    {
                        Response.Write("1");
                    }else if (row == 2)
                    {
                        Response.Write("2");
                    }
                    else
                    {
                        Response.Write("0");
                    }
                }
            }
        }
    }
}